{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}主题管理{/block}
<!-- CSS -->
{block name="css"}{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">主题管理 <small>themes</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            {if(check_auth('theme-create'))}<li><a data-toggle="modal" data-target="#modal-create"> <i class="icon icon-layout"></i> 上传主题</a></li>{/if}
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" action="{:url('/theme')}" method="get">
            <input type="text" class="form-control" placeholder="搜索" name="keywords" value="{$keywords}">
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
</div>
<div class="cards">
    {volist name="list" id="vo"}
    <div class="col-md-3 col-sm-6">
        <div class="card">
            <div class="media-wrapper"><img class="img-bg img-4x3" style="background-image: url({$vo['theme_image']});"></div>
            {if ($vo['theme_description']!='')} <div class="caption">{:sub_str($vo['theme_description'], 100)}</div>{/if}
            <h4 class="card-heading">{$vo['theme_name']}</h4>
            <div class="card-content text-muted">
                <span class="pull-right">版本：{$vo['theme_version']}</span>
                作者：{$vo['theme_author']}
            </div>
            <div class="card-actions">
                {if ($vo['theme_default'])}
                <div class="pull-right">
                    <a class="text-muted"><i class="icon icon-trash"></i> 删除</a>
                </div>
                <button type="button btn-sm" class="btn btn-sm btn-success"><i class="icon icon-checked"></i> 启用</button>
                {else /}
                    <div class="pull-right">
                        {if(check_auth('theme-delete'))}
                            <a class="delete text-danger" data-url="{:url('/theme/delete','mark='.$vo['theme_mark'])}"><i class="icon icon-trash"></i> 删除</a>
                        {else /}
                            <a class="text-muted"><i class="icon icon-trash"></i> 删除</a>
                        {/if}
                    </div>
                    {if(check_auth('theme-switch'))}
                        <button type="button" class="btn btn-sm btn-warning startup" data-mark="{$vo['theme_mark']}"><i class="icon icon-check-empty"></i> 点击启用</button>
                    {else /}
                        <button type="button" class="btn btn-sm btn-warning" disabled="true"><i class="icon icon-check-empty"></i> 点击启用</button>
                    {/if}
                {/if}
            </div>
        </div>
    </div>
    {/volist}
    {empty name="list"}
    <div class="mb20 mt20 text-center">
        {if ($keywords!='')}
            未搜索到 “{$keywords}” 相关的主题 &nbsp; <a href="{:url('/theme')}">查看全部主题</a>
        {else /}
            暂未添加主题
        {/if}
    </div>
    {/empty}
</div>
{include file="theme/create" /}
{/block}


<!-- JS -->
{block name="js"}
    {load href="/static/lib/jquery/jquery.form.js"}
    {load href="/static/lib/jquery/jquery.autofill.min.js"}
    {load href="/static/lib/validator/validator.min.js"}
    {load href="/static/lib/simpleupload/simpleUpload.min.js"}
{/block}
{block name="jscode"}
<script type="text/javascript">
$(document).ready(function() {
    $("#btn_theme_file").click(function(event) {
        var settings = {
            uploadUrl: "{:url('/upload/theme_file')}",
            accept: "application/zip",

            allowedExts: ["zip"],
        };

        var startFunc = function(file) {
            sxj.loading(); //console.log("upload started");
        }

        // 回调函数
        var successFunc = function(response) {
            sxj.msg_success('文件上传成功');
            var data = response.data;
            console.log("upload successful!");
            $("#theme_file").val(data.file_path)
        }

        // 调用上传插件
        sxj.upload(settings, successFunc, startFunc);
    });

    $(".startup").click(function(event) {
        var mark = $(this).data('mark');
        sxj.ajax_post("{:url('/theme/startup')}", { mark: mark });
    });
});
</script>
{/block}